<template>  
<div style="width:100vw; height:100vh;postion:relative;">
    <div class="headers">
        <el-row>
            <el-col :span ="3" style="margin-left:5%;">
                <!-- <img style="padding-top:10px;width:70%;height:50px;" src="../../assets/img/logo.png" alt=""> -->
            </el-col>
            <el-col :span="8" style="margin-left:10%;">
                <h2> SASS</h2>
            </el-col>
        </el-row>
    </div>
    <div class="login-wrap">
        <div class="ms-login">
            <div class="ms-title">scss</div>
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="0px" class="ms-content">
                <el-form-item prop="phone">
                    <el-input v-model="ruleForm.username" placeholder="phone">
                        <el-button slot="prepend" icon="el-icon-user"></el-button>
                    </el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input
                        type="password"
                        placeholder="password"
                        v-model="ruleForm.password"
                        @keyup.enter.native="submitForm()"
                    >
                        <el-button slot="prepend" icon="el-icon-lock"></el-button>
                    </el-input>
                </el-form-item>
                <div class="login-btn">
                    <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
                </div>
                <p class="login-tips"></p>
            </el-form>
        </div>
    </div>
    <div class="footer">
        <p>技术支持：三生清源/成都原链</p>
    </div>
</div>
    
</template>

<script>
import {login} from '@/request/api'
import SIdentify from '../common/authcode'
export default {
	inject: ['reload'], 
    components: { SIdentify },
    data: function() {
        return {
            isgt: false,
            identifyCodes:'z645xcvbnml786kjhfgda453sqerty579uiop12347890',
            identifyCode:'',    
            code:'',
            ruleForm: {
                username: '',
                password: '',
                num:''
            },
            rules: {          
                username: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
                
            },
        };
    },

    created(){
		// var httpurl = "http://" + window.location.host + "/"
		// localStorage.setItem("requestUrl",httpurl)
		localStorage.setItem("requestUrl","http://39.96.59.234:8886")
		// localStorage.setItem("requestUrl","http://192.168.0.100:8884")
    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid)=>{
				if(valid){
					login({
						username:this.ruleForm.username, 
						password:this.ruleForm.password,
					}).then(res=>{
                         if(res.appMenus && res.appMenus.length>0){
                            this.$notify({
								title: '提示',
								message: '登录成功',
								type: 'success',
								duration:1000
							  });
                            this.$util.set("userInfo",res);
                            localStorage.setItem("headImg",res.userInfo.headImg)
                            localStorage.setItem("companyId",res.userInfo.companyId)
                            localStorage.setItem("userType",res.userInfo.userType)
							localStorage.setItem("requestUrl",res.appMenus[0].appUrl)
							console.log(localStorage.getItem("requestUrl"))
							// console.log(localStorage.setItem("requestUrl",res.appMenus[0].appUrl))
                            this.$store.commit("setuserid",res.userInfo.id)
                            localStorage.setItem('ms_username', this.ruleForm.username);
                            localStorage.setItem('ms_id', res.userInfo.id);
							// localStorage.setItem('tabtype',"sss")
							sessionStorage.setItem('setTabStatus',"sss")
                            // this.$store.commit("setTabStatus","sss")
                            this.$store.commit('setname',this.ruleForm.username)
                            this.$store.commit('settoken',res.token)
							if(res.appMenus[0].configMenus.length>0){
								localStorage.setItem("system","show")
								 this.$store.commit("setsystem",res.appMenus[0].configMenus)
							}else{
								localStorage.removeItem("system")
							}
                            this.$router.push({path:'/home'});
							// this.reload()
                        }else{
                              this.$notify({
                                title: '提示',
                                message: '没有应用权限,请联系管理员开通',
                                type: 'error',
                                duration:1000
                            });
                        }
                      
					})
				}else{
					return false
				}
			})
        },
    },
};
</script>


<style scoped>
.footer{
    width:100%;
    height:4vh;
    bottom:20px;
    /* left:50%; */
    position: absolute;
    text-align:center;
    line-height:4vh;
    font-size:14px;
    color:white;
}
.headers{
    width:100%;
    height:8vh;
    top:0;
    left:0;
    position: absolute;
    z-index:9999;
    background:rgba(255, 255, 255, 0.5);
    line-height: 8vh;
}
.el-col{
    margin-top:0;
}
.login-wrap {
    position: relative;
    width: 100%;
    height: 100vh;
    background-image: url(../../assets/img/login-bg.jpg);
    background-size: 100%;
}
.ms-title {
    width: 100%;
    line-height: 50px;
    text-align: center;
    font-size: 20px;
    color: #fff;
    border-bottom: 1px solid #ddd;
}
.ms-login {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 350px;
    margin: -190px 0 0 -175px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.3);
    overflow: hidden;
}
.ms-content {
    padding: 30px 30px;
}
.login-btn {
    text-align: center;
}
.login-btn button {
    width: 100%;
    height: 36px;
    margin-bottom: 10px;
}
.login-tips {
    font-size: 12px;
    line-height: 30px;
    color: #fff;
}
</style>